# Maintainer: Lukas Jirkovsky <l.jirkovsky@gmail.com>
pkgname=cdrtools
pkgver=3.02a09
pkgrel=5
pkgdesc="Original cdrtools supporting CD, DVD and BluRay burning"
arch=('loong64' 'x86_64')
url="http://cdrecord.org/"
license=('CDDL')
depends=('acl' 'libcap')
conflicts=('cdrkit')
provides=('cdrkit')
replaces=('cdrkit')
options=(!makeflags)
backup=('etc/default/cdrecord' 'etc/default/rscsi')
source=(https://downloads.sourceforge.net/cdrtools/cdrtools-$pkgver.tar.bz2
    cdrtools-la64.patch)
sha256sums=('aa28438f458ef3f314b79f2029db27679dae1d5ffe1569b6de57742511915e81'
            '2a3925ae1293a84277179497d7f0f17789447f8fa72c90f012ac36d36b3edc30')
install=cdrtools.install

prepare() {
  cd "$srcdir"/cdrtools-${pkgver%%a*}
	patch -p1 -i "$srcdir/cdrtools-la64.patch"
}

build() {
  cd "$srcdir"/cdrtools-${pkgver%%a*}
  sed -i 's|/opt/schily|/usr|g' DEFAULTS/Defaults.linux
  sed -i 's|DEFINSGRP=.*|DEFINSGRP=root|' DEFAULTS/Defaults.linux
  # install rscsi to /usr/bin instead of /usr/sbin
  sed -i 's|INSDIR=.*|INSDIR=bin|' rscsi/Makefile

  export GMAKE_NOWARN=true
  make INS_BASE=/usr INS_RBASE=/ VERSION_OS="_ArchLinux" LDOPTX="$LDFLAGS"
}

check() {
  cd "$srcdir"/cdrtools-${pkgver%%a*}
  make tests
}

package() {
  cd "$srcdir"/cdrtools-${pkgver%%a*}

  export GMAKE_NOWARN=true
  make INS_BASE=/usr INS_RBASE=/ DESTDIR="$pkgdir" install

  # remove unneeded files that may cause conflicts
  rm -rf "$pkgdir"/usr/include
  rm -rf "$pkgdir"/usr/lib/{*.a,profiled}
  rm -rf "$pkgdir"/usr/share/man/man3

  # autoload 'sg' module needed by cdrecord
  install -d -m755 "$pkgdir"/usr/lib/modules-load.d/
  echo sg > "$pkgdir"/usr/lib/modules-load.d/cdrecord.conf

  # create symlinks for cdrkit compatibility
  cd "$pkgdir"/usr/bin
  ln -s cdrecord wodim
  ln -s readcd readom
  ln -s mkisofs genisoimage
  ln -s cdda2wav icedax
}

# vim:set ts=2 sw=2 et:
